home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_139 / warranger / warranger.asm < prev    next >
Assembly Source File  |  1992-05-06  |  14KB  |  484 lines

  1. ;*****************************************************************************
  2. ;*
  3. ;*        WindowArranger.asm (assembler version)        29.2.88
  4. ;*                        by Heiko Rath
  5. ;*
  6. ;* This little goodie is able to send a window to front or back. I wrote it
  7. ;* for a friend (<CB>) who wanted to bring his AmiCron window to front if  
  8. ;* something of interest happened in this window.
  9. ;*
  10. ;* A short description:
  11. ;* The program first trys to open the 'dos.library', if it had success to do
  12. ;* so it trys to parse your input string. If it can't understand what you want
  13. ;* it gives you help how to use it. If it is able to parse your input it trys
  14. ;* to open 'intuition.library' and to find a window with a matching name. If
  15. ;* there is one it rearranges it to front or to back. After this it closes
  16. ;* the 'intuition.library' & the 'dos.library'.
  17. ;*
  18. ;* This program was compiled using Asm68K.
  19. ;*
  20. ;* Thanx to Larry Phillips, (CIS -76703,4322) & C.Heath.
  21. ;*****************************************************************************
  22. ;*
  23. ;*        !!!!!!!!COPY ME FAST, I WANT TO TRAVEL!!!!!!!!
  24. ;*
  25. ;* This program is public domain. Feel free to copy and modify it. If you
  26. ;* like it you can do one of the following things:
  27. ;*
  28. ;* 1.    absolutly nothing
  29. ;* 2.    send me something I deserve:
  30. ;*                money, yachts, beer, Marabou chocolate
  31. ;* 3.    contact us
  32. ;*
  33. ;*                Heiko Rath
  34. ;*                Raiffeisenstr.10a
  35. ;*                D-6108 Weiterstadt
  36. ;*                WEST GERMANY
  37. ;*                Tel.06150-2658
  38. ;*
  39. ;*                                     or
  40. ;*                          
  41. ;*______  /          
  42. ;*______\O                    - The Software Brewery - 
  43. ;*      \\                          
  44. ;*       o            Sparkling, fresh software from W.-Germany
  45. ;*                 
  46. ;*     @@@@@          Straight from the bar to your system
  47. ;*     |~~~|\        
  48. ;*     | | |/        
  49. ;*     |___|        With our regards to the Software Distillery
  50. ;*
  51. ;*Members are (listed alphabetically):
  52. ;*Christian Balzer alias <CB>, Lattice C, user interfaces, beer addict. 
  53. ;*Christof Bonnkirch, Aztec C, telecommunications, beer adict.
  54. ;*Heiko Rath alias <HR>, Assembler, ROM-Kernal stuff, Marabou addict. 
  55. ;*Peter Stark alias PS, Lattice C, IO & utilities, WordStar addict.
  56. ;*Ralf Woitinas alias RAF, Assembler, anything, Ray-Tracing addict.
  57. ;*Torsten Wronski alias MM, Assembler, anything, girls addict.
  58. ;*
  59. ;*Beverages: Altenmuenster Brauer Bier, Urfraenkisches Landbier, Grohe Bock.
  60. ;*
  61. ;*Send exotic drinks, beautyfull girls, $$$$, comments, critizism, flames to:
  62. ;*
  63. ;*The Software Brewery
  64. ;*Christian Balzer
  65. ;*Im Wingertsberg 45
  66. ;*D-6108 Weiterstadt
  67. ;*West-Germany
  68. ;*
  69. ;*Our BBS "AmigaNode" isn't online yet. As soon as it becomes available, 
  70. ;*you'll be the first to know :-).
  71. ;*
  72. ;*
  73.  
  74. ExecBase    Equ    4
  75.  
  76. ;*** Exec Offsets:
  77. FindTask    Equ    -294    ;(name)(a1)
  78. WaitPort    Equ    -384    ;(port)(a0)
  79. GetMsg        Equ    -372    ;(port)(a0)
  80. ReplyMsg    Equ    -378    ;(message)(a1)
  81. Forbid        Equ    -132    ;()()
  82. OpenLibrary    Equ    -552    ;(libName,version)(a1,d0)
  83. CloseLibrary    Equ    -414    ;(library)(a1)
  84. OldOpenLibrary    Equ    -408
  85. CLOSEWINDOW    Equ    $200    ;IDCMP-Flag CloseWindow
  86. WD_USERPORT    Equ    86    ;WD_UserPort
  87. IM_CLASS    Equ    20    ;Even Class
  88.  
  89. ;*** DOS Offsets:
  90.  
  91. Input        Equ    -54    ;()
  92. OutPut        Equ    -60    ;()
  93. Write        Equ    -48    ;(file, buffer, length)(d1,d2,d3)
  94.  
  95. ;*** Intuition Offsets:
  96.  
  97. OpenWindow    Equ    -204    ;(OWArgs)(a0)
  98. CloseWindow    Equ    -72    ;(Window)(a0)
  99. LockIBase    Equ    -414    ;(dontknow)(d0)
  100. UnlockIBase    Equ    -420    ;(IBlock)(a0)
  101. WindowToFront    Equ    -312    ;(Window)(a0)
  102. WindowToBack    Equ    -306    ;(Window)(a0)
  103. AutoRequest    Equ    -348    ;(Window,body,PText,NText,PFlags,NFlags,W,H)
  104.                 ;(a0,a1,a2,a3,d0,d1,d2)
  105.  
  106. timer        Equ    0
  107. GfxBase        Equ    2
  108. fac        Equ    6
  109. PR_CLI        Equ    172
  110. PR_MsgPort    Equ    92
  111.  
  112. ;*** Macro Definitions:
  113. push.w    MACRO
  114.     move.w    \1,-(sp)    ;push a word onto stack
  115.     ENDM
  116.  
  117. push.l    MACRO
  118.     move.l    \1,-(sp)    ;push a longword onto stack
  119.     ENDM
  120.  
  121. pop.w    MACRO
  122.     move.w    (sp)+,\1    ;pop a word from stack
  123.     ENDM
  124.  
  125. pop.l    MACRO
  126.     move.l    (sp)+,\1    ;pop a longword from stack
  127.     ENDM
  128.  
  129. pushm    MACRO
  130.     movem.l    \1,-(sp)    ;push several register on stack
  131.     ENDM
  132.  
  133. popm    MACRO
  134.     movem.l    (sp)+,\1    ;pop several register from stack
  135.     ENDM
  136.  
  137.  
  138. Amiga_Init:
  139.     move.l    sp,d6            ;save stack pointer
  140.  
  141.     move.l    a0,a2            ;register a2 is cmdline henceforth
  142.     clr.b    0(a2,d0.w)        ;make sure that cmdline is null terminated
  143.     push.w    d0            ;save cmdlength
  144.  
  145.     move.l    ExecBase,a6        ;get ExecBaseaddress to a6
  146.     suba.l    a1,a1            ;clear a1
  147.     jsr    FindTask(a6)        ;get pointer
  148.  
  149.     move.l    d0,a4            ;get process-pointer to a4
  150.     tst.l    PR_CLI(a4)        ;pr_CLI: CLI or WB?
  151.     bne    main            ;if <> 0 then CLI
  152.  
  153. fromWB:
  154.     lea    PR_MsgPort(a4),a0    ;pr_MsgPort: messageportaddress to a0
  155.     jsr    WaitPort(a6)        ;wait until message arrives
  156.     lea.l    PR_MsgPort(a4),a0    ;
  157.     jsr    GetMsg(a6)        ;get message
  158.     move.l    d0,a5            ;save return message in a5
  159.     moveq.l    #0,d0            ;any version
  160.     lea.l    INTName,a1        ;get address of libraryname to a1
  161.     jsr    OpenLibrary(a6)        ;try to open Intuition
  162.     tst.l    d0            ;see if d0 = 0
  163.     beq    ErrorExit        ;ohh shit, failed to open Intuition
  164.     move.l    d0,a6            ;get Baseaddress of Intuition to a6
  165.     moveq.l    #0,d0            ;PFlag = 0
  166.     moveq.l    #0,d1            ;NFlag = 0
  167.     move.l    #320,d2            ;width 320
  168.     move.l    #68,d3            ;height 68
  169.     suba.l    a0,a0            ;clear a0
  170.     lea.l    ITextId,a1        ;get address of ITextId to a1
  171.     suba.l    a2,a2            ;PosText = 0
  172.     lea.l    ITextOk,a3        ;get address of NegText to a3
  173.     jsr    AutoRequest(a6)        ;display Autorequest
  174.     move.l    a6,a1            ;get INTBase to a1
  175.     move.l    ExecBase,a6        ;get ExecBase to a6
  176.     jsr    CloseLibrary(a6)    ;close Intuition
  177.  
  178.     jsr    Forbid(a6)        ;we have to do this, so that WB can't
  179.                     ; unload us to far
  180.     move.l    a5,a1            ;get address of ReturnMessage to a1
  181.     jsr    ReplyMsg(a6)        ;reply the message
  182.     pop.w    d0
  183. ErrorExit:
  184.     rts
  185.  
  186. main:
  187.     move.l    ExecBase,a6        ;ExecBase to a6
  188.     lea    DOSName(pc),a1        ;Address of string 'dos.library',0
  189.     jsr    OldOpenLibrary(a6)    ;open library
  190.     move.l    d0,DOSBase        ;save DOSBaseaddress
  191.     beq    Exit            ;if d0=0 then Exit (System is realy sick!)
  192.     move.l    D0,A6            ;move DOSBasepointer to a6
  193.     jsr    OutPut(A6)        ;identify the initial output handle
  194.     move.l    D0,stdout        ;save stdout
  195.  
  196.     pop.w    d0            ;get cmdlength
  197. SkipSP:    
  198.     move.b    (a2)+,d1        ;skip spaces
  199.     beq.b    ShowHow            ;if NULL-String then /* help */
  200.     cmp.b    #' ',d1            ;is it a Space ?
  201.     beq.b    SkipSP            ;yes -> SkipSP
  202.  
  203.     sub.l    #1,a2
  204.     move.l    a2,StringAddress    ;store windownamestart
  205.     add.l    #1,a2
  206.  
  207.     cmp.b    #$0a,d1            ;is it #$0a ?
  208.     beq.b    ShowHow            ;yes -> ShowHow /* help */
  209.  
  210.     cmp.b    #'?',d1            ;is it '?' ?
  211.     beq.b    ShowHow            ;yes -> ShowHow /* help required */
  212.  
  213.     cmp.b    #'"',d1            ;is it '"' ?
  214.     beq.b    DoQuotes        ;yes -> DoQuotes
  215.  
  216. DoTheMainParsing:
  217.     cmp.b    #'-',d1            ;is it '-' ?
  218.     beq.b    Parser            ;yes -> Parser /* see if -f or -b */
  219.     move.b    (a2)+,d1        ;get the next byte
  220.     bne.b    DoTheMainParsing    ;-> DoTheMainParsing
  221.  
  222. ShowHow:
  223.     lea    HelpString(pc),a0    ;give the user help
  224.     move.l    a0,d2            ;copy address of string to d2
  225.     bsr    TextOutPut        ;output text via Amiga-Dog
  226.     bra    DosClose        ;close DOS
  227.  
  228. DoQuotes:
  229.     move.l    a2,StringAddress    ;store address of string
  230. QuotesLoop:
  231.     move.b    (a2)+,d1        ;get the next character
  232.     beq.b    ShowHow            ;if we have reached the end -> ShowHow
  233.     cmp.b    #'"',d1            ;is it '"' ?
  234.     bne.b    QuotesLoop        ;no ->QuotesLoop
  235.     move.b    #0,-(a2)        ;clear the last '"'
  236.     addq.l    #1,a2
  237.     bra.b    DoTheMainParsing    ;-> DoTheMainParsing
  238.  
  239.  
  240. Parser:
  241.     move.b    #0,-(a2)
  242.  
  243.     add.l    #1,a2
  244.     move.b    (a2),d1
  245.     and.b    #%11011111,d1        ;convert lowercase to uppercase
  246.     cmp.b    #'F',d1
  247.     beq.b    Front
  248.     cmp.b    #'B',d1
  249.     beq.b    Back
  250.     bra.b    ShowHow
  251.  
  252. Front:    push.w    #'FR'            ;this is only to remember that the user
  253.                     ; wanted '-f'
  254.     bra.b    Intuitionopen
  255.  
  256. Back:    push.w    #'BA'
  257.  
  258. Intuitionopen:                ;try to open Intuition
  259.     move.l    ExecBase,a6
  260.     lea    INTName,a1
  261.     jsr    OldOpenLibrary(a6)
  262.     move.l    d0,IntuitionBase    ;save IntuitionBase
  263.     beq    DosClose        ;if d0=0 then DosClose (Unable to open Intuition)
  264.     move.l    d0,a6            ;copy IntuitionBase to a6
  265.     moveq    #0,d0            ;clear d0
  266.     jsr    LockIBase(a6)        ;lock Intuition
  267.     move.l    d0,MyLock        ;store lock
  268.  
  269.     move.l    60(a6),d0        ;get address of first screen
  270.     beq    NoScreen        ;if d0=0 then /* there is no
  271.                     ; Screen !? */
  272.     move.l    d0,ScreenPointer    ;store address of screen
  273.     move.l    d0,a0
  274. GetFirst:
  275.     move.l    4(a0),d0        ;get address of 1. Window
  276.     move.l    d0,a2
  277.     tst.l    d0            ;is d0=0?
  278.     beq    NextScreen        ;if a2=0 then /* there is no
  279.                     ; window in this screen */
  280. ****                         ****
  281. * Compare the name of the windowtitle with a string *
  282. * if equal then rearrange window            *
  283. *****                         ****
  284. DoCompare:
  285.     move.l    StringAddress,a1    ;get address of String to a1
  286.     move.l    32(a2),a0        ;get address of windowtitle to a0
  287. 001$:
  288.     move.b    (a0)+,d0        ;copy one byte to d0
  289.     move.b    (a1)+,d1        ;copy one byte to d1
  290.     and.b    #%11011111,d0        ;convert lowercase to uppercase
  291.     and.b    #%11011111,d1        ;convert lowercase to uppercase
  292.     cmp.b    d0,d1            ;see if equal
  293.     bne.b    NotTheSame        ;if no then -> NotTheSame    
  294.     tst.b    d0            ;see if NULL
  295.     beq.b    Same            ;if yes then -> Same
  296.     bra.b    001$            ;-> 001$
  297.  
  298. NotTheSame:
  299.     move.l    (a2),d0            ;get address of next window
  300.     move.l    d0,a2            ;copy address to a2
  301.     tst.l    d0            ;is d0=0?
  302.     bne.b    DoCompare        ;look at the next windowtitle
  303.                     ;if a2=0 then/* this was the last window */
  304. NextScreen:
  305.     move.l    ScreenPointer,a0
  306.     move.l    (a0),a0            ;get address of next screen
  307.     move.l    a0,d0
  308.     tst.l    d0            ;is a0=0?
  309.     beq    NotFound        ;if a0=0 then /* no more screens */
  310.     bra.b    GetFirst        ;get first windowaddress
  311.  
  312. NotFound:
  313.     pop.w    d0
  314.     lea    HelpString(pc),a0    ;get address of Helpstring to a0
  315.     move.l    a0,d2            ;copy address to d2
  316.     bsr    TextOutPut        ;output text
  317.     lea    NotFoundString(pc),a0    ;get address of NotFoundString to a0
  318.     move.l    a0,d2            ;copy address to d2
  319.     bsr    TextOutPut        ;output text
  320.     bra.b    NoScreen        ;-> NoScreen
  321.  
  322. Same:
  323.     move.l    a2,a0            ;copy windowaddress to a0
  324.     pop.w    d0
  325.     cmp.w    #'BA',d0
  326.     beq.b    MoveToBack 
  327.     jsr    WindowToFront(a6)    ;window to front
  328.     bra.b    NoScreen
  329.  
  330. MoveToBack:
  331.     jsr    WindowToBack(a6)    ;window to back
  332.  
  333. NoScreen:
  334.     move.l    MyLock,a0        ;get lockvalue
  335.     jsr    UnlockIBase(a6)        ;unlock Intuition
  336.  
  337. Intuitionclose:                ;close Intuition
  338.     move.l    ExecBase,a6
  339.     move.l    IntuitionBase,a1
  340.     jsr    CloseLibrary(a6)
  341.  
  342. DosClose:                ;close Amiga-DOG
  343.     move.l    ExecBase,a6
  344.     move.l    DOSBase,a1
  345.     jsr    CloseLibrary(a6)
  346. Exit:
  347.     move.l    #0,d0            ;no return-error
  348.     rts
  349.  
  350. ;*****************************************************************************
  351. ;*
  352. ;*    TextOutPut
  353. ;*            by    Heiko Rath
  354. ;*                Raiffeisenstr.10a
  355. ;*                D-6108 Weiterstadt
  356. ;*                West Germany
  357. ;*                Tel.06150-2658
  358. ;*                          
  359. ;*______  /          
  360. ;*______\O                    - The Software Brewery - 
  361. ;*      \\                          
  362. ;*       o            Sparkling, fresh software from W.-Germany
  363. ;*                 
  364. ;*     @@@@@          Straight from the bar to your system
  365. ;*     |~~~|\        
  366. ;*     | | |/        
  367. ;*     |___|        With our regards to the Software Distillery
  368. ;*
  369. ;*Members are (listed alphabetically):
  370. ;*Christian Balzer alias <CB>, Lattice C, user interfaces, beer addict. 
  371. ;*Christof Bonnkirch, Aztec C, telecommunications, beer adict.
  372. ;*Heiko Rath alias <HR>, Assembler, ROM-Kernal stuff, Marabou addict. 
  373. ;*Peter Stark alias PS, Lattice C, IO & utilities, WordStar addict.
  374. ;*Ralf Woitinas alias RAF, Assembler, anything, Ray-Tracing addict.
  375. ;*Torsten Wronski alias MM, Assembler, anything, girls addict.
  376. ;*
  377. ;*Beverages: Altenmuenster Brauer Bier, Urfraenkisches Landbier, Grohe Bock.
  378. ;*
  379. ;*
  380. ;* PURPOSE:         output a NULL-terminated string via stdout
  381. ;*
  382. ;* ROUTINE TYPE:     subroutine
  383. ;*
  384. ;* SYNTAX:        bsr    TextOutPut    (stringaddress)(d2)
  385. ;*
  386. ;* ENTRY CONDITIONS:    needs DOSlibrary opened and stdout defined
  387. ;*            also needs DOS-'Write' offset -48 defined.
  388. ;*
  389. ;* RETURNS:        Text via DOS-stdout
  390. ;*
  391. ;* NOTE:        its better if the string is really NULL-terminated
  392. ;*
  393. ;* CHANGED:        nothing
  394. ;*
  395. ;* USAGE:        move.l    #Textaddress,d2
  396. ;*            bsr    TextOutPut
  397. ;*
  398. ;*****************************************************************************
  399.  
  400.  
  401.  
  402. TextOutPut:        ;TextOutPut (Textaddress)(d2)
  403.             ;prints a NULL-terminated string via stdout
  404.             ;changed: nothing
  405.     movem.l    d0-d7/a0-a6,-(sp)    ;save registers
  406.     move.l    d2,a0            ;address to a0
  407.     clr.l    d3            ;count = 0
  408. CountLoop:
  409.     tst.b    (a0)+            ;is it NULL ?
  410.     beq.b    PMsg            ;yes: -=> determine length
  411.     addq.l    #1,d3            ;count = count+1
  412.     bra.b    CountLoop        ;test next byte
  413. PMsg:
  414.     move.l    stdout,d1        ;get stdout to d1
  415.     move.l    DOSBase,a6        ;move DOSBase to a6
  416.     jsr    Write(a6)        ;write the Text
  417.     movem.l    (sp)+,a0-a6/d0-d7    ;reserve registers
  418.     rts
  419.  
  420. ;*** variables:
  421.  
  422. DOSBase        dc.l    0            ;pointer to the DOSBaseaddress
  423. stdout        dc.l    0            ;pointer to standard output
  424. IntuitionBase:                    ;address of Intuitionbase
  425.         dc.l    0
  426. UserPort:
  427.         dc.l    0
  428. MyLock        dc.l    0
  429. ScreenPointer    dc.l    0
  430. StringAddress    dc.l    0
  431.  
  432.         cnop    0,2
  433. ;*** constants:
  434. DOSName        dc.b    'dos.library',0        ;name of the DOS-library
  435. INTName        dc.b    'intuition.library',0    ;name of the Intuition-library
  436.  
  437.         cnop    0,2
  438.  
  439. HelpString:    dc.b    $9b,'0;33;40m','WindowArranger',$9b,'0;31;40m'
  440.         dc.b    ' by ',$9b,'0;32;40m','Heiko Rath ',$9b,'0;31;40m'
  441.         dc.b    $9b,'4;31;40m',169,' by '
  442.         dc.b    $9b,'1;31;40m','The Software Brewery',$9b,'0;31;40m',10
  443.         dc.b    'To arrange a window use ',$9b,'0;33;40m'
  444.         dc.b    'WindowArranger name -f',$9b,'0;31;40m',' or '
  445.         dc.b    $9b,'0;33;40m','-b',$9b,'0;31;40m',10
  446.         dc.b    $9b,'1;31;40m','f',$9b,'0;31;40m'
  447.         dc.b    '= window to front & '
  448.         dc.b    $9b,'1;31;40m','b',$9b,'0;31;40m'
  449.         dc.b    '= window to back',10
  450.         dc.b    0
  451.         cnop    0,2
  452. NotFoundString:
  453.         dc.b    $9b,'0;32;40m','Please give me a babel fish'
  454.         dc.b    ' or a new windowname!!',$9b,'0;31;40m',10,0
  455.  
  456.         cnop    0,2
  457. ******************************************************************************
  458. *
  459. *    This is the IntuitionTextStructure of the AutoRequester
  460. *
  461. ******************************************************************************
  462. ITextId:    dc.b    0,1,1,0         ;pens, drawmode and filler
  463.         dc.w    17,6         ;XY
  464.         dc.l    0         ;NULL for default font
  465.         dc.l    S1          ;pointer to text
  466.         dc.l    ITextId2     ;next IntuitText structure
  467. ITextId2    dc.b    0,1,1,0
  468.         dc.w    17,18
  469.         dc.l    0
  470.         dc.l    S2
  471.         dc.l    0
  472. ITextOk:    dc.b    0,1,1,0
  473.         dc.w    6,3
  474.         dc.l    0
  475.         dc.l    SOk
  476.         dc.l    0
  477.         cnop    0,2
  478. S1        dc.b    'WindowArranger must be',0
  479.         cnop    0,2
  480. S2        dc.b    'started from the CLI.',0
  481.         cnop    0,2
  482. SOk        dc.b    'Ok',0
  483.         cnop    0,2
  484.